package Test.Test02;

import java.util.*;

class A {
    //小米笔试AC
    public static void main(String[] args) {
        System.out.println(fun(5));
    }

    public static int fun(int n) {
        int flag = 0;
        Queue<Integer> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(i + 1);
        }
        while (queue.size() != 1) {
            flag++;
            if (flag % 3 == 0) {
                queue.poll();
            }else{
                queue.add(queue.poll());
            }
        }
        return queue.poll();
    }

    public static void merge(int[] a, int[] b) {
        int aIndex = 0, bIndex = 0;

        int m = a.length, n = b.length;
        int [] arr = new int[m];
        for (int i = 0; i < m; i++) {
            if (a[aIndex] < b[bIndex]) {
                arr[i] = a[aIndex];
                aIndex++;
            }else{
                arr[i] = b[bIndex];
                bIndex++;
            }
        }
        System.arraycopy(arr, 0, a, 0, m);
    }
}